{% extends "accounts/base.html" %}
{% load rollup accounts_tags %}

{% block title %}{{ block.super }} - Summary{% endblock %}

{% block extrahead %}
<link href="/media/css/accounts.css" rel="stylesheet" type="text/css" />
{% endblock %}

{% block breadcrumbs %}
<a href="{% url summary %}">Summary</a>
{% endblock %}

{% block content %}
<table id="summary">
	<tr class="even">
		<td>MTD Expenses</td>
		<td class="money negative">{{ expenses|monthly_balance|rollup:"monthly"|floatformat:2 }}</td>
		<td>YTD Expenses</td>
		<td class="money negative">{{ expenses|yearly_balance|rollup:"yearly"|floatformat:2 }}</td>
	</tr>
	<tr class="odd">
		<td>MTD Revenue</td>
		<td class="money positive">{{ revenues|monthly_balance|rollup:"monthly"|floatformat:2 }}</td>
		<td>YTD Revenue</td>
		<td class="money positive">{{ revenues|yearly_balance|rollup:"yearly"|floatformat:2 }}</td>
	</tr>
	<tr class="even">
		<td>MTD Total</td>
		<td class="money total">{% rollup_total "%.2f" "monthly" %}</td>
		<td>YTD Total</td>
		<td class="money total">{% rollup_total "%.2f" "yearly" %}</td>
	</tr>
</table>

<table id="accounts"><tr>
		<td valign="top">
			<table>
				<thead>
					<tr class="header">
						<th>Assets</th>
					</tr>
					<tr>
						<td>Account</td>
						<td>Total</td>
					</tr>
				</thead>
				{% for account in assets %}
				<tr class="{% cycle 'even' 'odd' %}">
					<td class="{{ account.type|lower }}">
						<a href="{% url ledger account.pk %}">{{ account.name }}</a>
					</td>
					<td class="money">
						{% with account|monthly_balance as balance %}
						<span style="font-size: 8pt;">{% if balance|gt:0 %}
							(<span class="money positive">+{{ balance|floatformat:0 }}</span>)
						{% else %}{% if balance|lt:0 %}
							(<span class="money negative">{{ balance|floatformat:0 }}</span>)
						{% endif %}
						{% endif %}</span>
						<strong class="money {% if account.has_normal_balance %}positive{% else %}negative{% endif %}">{{ account.normal_balance|rollup:"assets"|floatformat:0 }}</strong>
						{% endwith %}
					</td>
				</tr>
				{% endfor %}
				<tr class="total">
					<td class="right">Total:</td>
					<td class="money total">{% rollup_total "%.0f" "assets" %}</td>
				</tr>
			</table>
		</td>
		<td valign="top">
			<table>
				{% for type,accounts in income.iteritems %}

				<thead>
					<tr class="header">
						<th>{{ type }}</th>
					</tr>
					<tr>
						<td>Account</td>
						<td>{{ 2|get_months_back|date:"M" }}</td>
						<td>{{ 1|get_months_back|date:"M" }}</td>
						<td>{{ 0|get_months_back|date:"M" }}</td>
						<td>Bdt.</td>
					</tr>
				</thead>
				{% for account in accounts %}

				<tr class="{% cycle 'even' 'odd' %}">
					{% with account|monthly_balance:0 as balance %}
					{% with account|monthly_balance:1 as balance2 %}
					{% with account|monthly_balance:2 as balance3 %}

					<td class="{{ account.type|lower }}">
						<a href="{% url ledger account.pk %}">{{ account.name }}</a>
					</td>

					<td class="money {% if balance3|gte:0 %}positive{% else %}negative{% endif %}">
						{{ balance3|rollup:"monthly3"|default:""|floatformat:0 }}
					</td>
					<td class="money {% if balance2|gte:0 %}positive{% else %}negative{% endif %}">
						{{ balance2|rollup:"monthly2"|default:""|floatformat:0 }}
					</td>
					<td class="money {% if balance|gte:0 %}positive{% else %}negative{% endif %}">
						{{ balance|rollup:"monthly"|default:""|floatformat:0 }}
					</td>

					<td class="money positive">
					{% if account.budgeted_limit %}
						{{ account.budgeted_limit|rollup:account.type|floatformat:"0" }}
					{% endif %}
					</td>
					
					{% endwith %}
					{% endwith %}
					{% endwith %}
				</tr>
				{% endfor %}
				{% endfor %}

				<tr class="total">
					<td class="right">Total:</td>
					<td class="money total">{% rollup_total "%.0f" "monthly3" %}</td>
					<td class="money total">{% rollup_total "%.0f" "monthly2" %}</td>
					<td class="money total">{% rollup_total "%.0f" "monthly" %}</td>
					<td class="money total">{% rollup_total "%.0f" "Expense" %}</td>
				</tr>
				
				{% for type,accounts in oe.iteritems %}

				{% if accounts.count %}
				<thead>
					<tr class="header" style="border-bottom: 2px solid">
						<th>{{ type }}</th>
					</tr>
					<tr>
						<td colspan="3">Account</td>
						<td colspan="2">Balance</td>
					</tr>
				</thead>
				{% for account in accounts %}

				<tr class="{% cycle 'even' 'odd' %}">

					<td colspan="3" class="{{ account.type|lower }}">
						<a href="{% url ledger account.pk %}">{{ account.name }}</a>
					</td>
					<td colspan="2" class="money {% if account.has_normal_balance %}positive{% else %}negative{% endif %}">
						{{ account.normal_balance|rollup:"monthly"|default:""|floatformat:0 }}
					</td>
				</tr>
				{% endfor %}
				{% else %}
				{% ifequal type "Equity" %}
				<tr>
					<td colspan="5">You need to create an Equity account</td>
				</tr>
				{% endifequal %}
				{% endif %}
				{% endfor %}

				<tr class="total">
					<td colspan="3" class="right">Total:</td>
					<td colspan="2" class="money total">{% rollup_total "%.0f" "monthly" %}</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

<div class="clear"></div>
{% endblock %}
